package com.stock.demo.function.home.view;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.stock.demo.R;
import com.stock.demo.adapter.LiveBroadcastAdapter;
import com.stock.demo.framework.ui.fragment.BaseNetFragment;
import com.stock.demo.model.LiveBroadcastBean;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Created by xuzhaoyu on 17-7-31.
 */

public class LiveBroadcastTypeFragment extends BaseNetFragment implements LiveBroadcastTypeView {

    private RecyclerView mRvList;
    private LiveBroadcastAdapter mBroadcastAdapter;

    public enum LiveType implements Serializable {
        PREVIEW,
        LIVING,
        REVIEW,
        MINE
    }

    public static final String ARGUMENT_KEY_TYPE = "argumentType";

    private View mView;

    @Override
    public void initView() {
        mRvList = (RecyclerView) mView.findViewById(R.id.rv_live_broadcast_type);
    }

    @Override
    public void initData() {
        onNetNext(new Object()).setNetComplete();
        ArrayList<LiveBroadcastBean> liveBroadcastBeen = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            LiveBroadcastBean liveBroadcastBean = new LiveBroadcastBean();
            liveBroadcastBeen.add(liveBroadcastBean);
        }
        Bundle arguments = getArguments();
        LiveType liveType = (LiveType) arguments.get(ARGUMENT_KEY_TYPE);
        if (liveType != null) {
            switch (liveType) {
                case PREVIEW:
                    mBroadcastAdapter = new LiveBroadcastAdapter(getContext(), liveBroadcastBeen, LiveType.PREVIEW);
                    break;
                case LIVING:
                    mBroadcastAdapter = new LiveBroadcastAdapter(getContext(), liveBroadcastBeen, LiveType.LIVING);
                    break;
                case REVIEW:
                    mBroadcastAdapter = new LiveBroadcastAdapter(getContext(), liveBroadcastBeen, LiveType.REVIEW);
                    break;
                case MINE:
                    mBroadcastAdapter = new LiveBroadcastAdapter(getContext(), liveBroadcastBeen, LiveType.MINE);
                    break;
            }
        } else {
            mBroadcastAdapter = new LiveBroadcastAdapter(getContext(), liveBroadcastBeen, LiveType.PREVIEW);
        }
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvList.setAdapter(mBroadcastAdapter);
    }

    @Override
    public View onCreateSuccessView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_live_broadcast_type, container, false);
        return mView;
    }

    @Override
    public void onReload(View v) {

    }
}
